//
// Created by liuml on 2018/10/19.
//

#ifndef XYMUSIC_XYFFMPEG_H
#define XYMUSIC_XYFFMPEG_H

#include "XYCallJava.h"
#include "pthread.h"
#include "XYAudio.h"
extern "C"
{

#include <libavformat/avformat.h>
#include <libavutil/time.h>
};

class XYFFmpeg {
public:
    XYCallJava *callJava = NULL;
    const char *url = NULL;
    pthread_t decodeThread;

    //统领全局的基本结构体。主要用于处理封装格式
    AVFormatContext *pFormatCtx = NULL;
    XYAudio *audio = NULL;

    XYPlayStatus *playStatus = NULL;

    pthread_mutex_t init_mutex;//初始化的线程锁
    bool exit = false;
    int duration = 0;
    pthread_mutex_t seek_mutex;//用于seek 的时候的线程锁


public:
    XYFFmpeg(XYPlayStatus *playStatus,XYCallJava *callJava, const char *url);

    ~XYFFmpeg();

    void prepared();

    void start();

    void decodeFFMpegThread();

    void pause();

    void resume();

    void release();

    void seek(int64_t secde);

    void setVolume(int percent);

    void setMute(int mute);

    void setPitch(float pitch);

    void setSpeed(float speed);

    int  getSampleRate();

    void startStopRecord(bool start);

    bool catAudioPlay(int start_time, int end_time, bool showPcm);
};

#endif //XYMUSIC_XYFFMPEG_H
